/* pfs82UpdateSign.cpp
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#include <packet/pfs82UpdateSign.h>
#include <wrapper/JavaStreamWrapper.h>

pfs82UpdateSign::pfs82UpdateSign()
    : McPacketFromServer(0x82), x(0), y(0), z(0), text1(""), text2(""), text3(""), text4("")
{
}

unsigned int pfs82UpdateSign::length()
{
    return 1 + 4 + 2 + 4 + 2 + 2 + 2 + 2 + text1.length() + text2.length() + text3.length() + text4.length();
}

int16_t pfs82UpdateSign::setField(uint8_t field, void* value)
{
    static int16_t slen;

    switch (field)
    {
        case 0:
        default: return 4;
        case 1: x = JavaStreamWrapper::readInt(value); return 2;
        case 2: y = JavaStreamWrapper::readShort(value); return 4;
        case 3: z = JavaStreamWrapper::readInt(value); return 2;
        case 4: slen = JavaStreamWrapper::readShort(value); return 2*slen;
        case 5: text1 = JavaStreamWrapper::readUTF(value, slen); return 2;
        case 6: slen = JavaStreamWrapper::readShort(value); return 2*slen;
        case 7: text2 = JavaStreamWrapper::readUTF(value, slen); return 2;
        case 8: slen = JavaStreamWrapper::readShort(value); return 2*slen;
        case 9: text3 = JavaStreamWrapper::readUTF(value, slen); return 2;
        case 10: slen = JavaStreamWrapper::readShort(value); return 2*slen;
        case 11: text4 = JavaStreamWrapper::readUTF(value, slen); return -1;
    }
}

int32_t pfs82UpdateSign::getX()
{
    return x;
}

int16_t pfs82UpdateSign::getY()
{
    return y;
}

int32_t pfs82UpdateSign::getZ()
{
    return z;
}

std::string pfs82UpdateSign::getText1()
{
    return text1;
}

std::string pfs82UpdateSign::getText2()
{
    return text2;
}

std::string pfs82UpdateSign::getText3()
{
    return text3;
}

std::string pfs82UpdateSign::getText4()
{
    return text4;
}


